<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <div id="app" class="wrap">
        <!-- 搜寻表单模块 -->
        <div class="search_form">
            <div class="logo">
                <img src="./images/logo.png" alt="">
            </div>
            <div class="form_group">
                <input class="input_search" placeholder="请输入查询天气" v-model="city" @keyup.enter="getWeather"></input>
                <button class="input_sub" @click="getWeather">搜索</button>
            </div>
            <div class="hotkey">
                <ul>
                    <li><a href="javascript:;" @click="hotKey('北京')">北京</a></li>
                    <li><a href="javascript:;" @click="hotKey('上海')">上海</a></li>
                    <li><a href="javascript:;" @click="hotKey('广州')">广州</a></li>
                    <li><a href="javascript:;" @click="hotKey('深圳')">深圳</a></li>
                    <li><a href="javascript:;" @click="hotKey('郑州')">郑州</a></li>
                </ul>
            </div>
        </div>
        <!-- 天气列表模块 -->
        <ul class="weather_list">
            <li v-for="(item,index) in weatherList">
                <div class="info_type"><span>{{item.type}}</span></div>
                <div class="info_temp">
                    <b>{{item.high}}</b>
                    ~
                    <b>{{item.low}}</b>
                </div>
                <div class="info_date"><span>{{item.date}}</span></div>
            </li>
        </ul>
    </div>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                city: '武汉',
                weatherList: []
            },
            methods: {
                getWeather: function () {
                    that = this;
                    // console.log(this.city);
                    axios.get('http://wthrcdn.etouch.cn/weather_mini?city=' + this.city)
                        .then(function (res) {
                            console.log(res);
                            // console.log(res.data.data.city);
                            that.weatherList = res.data.data.forecast;
                        }, function (err) {
                            console.log(err);
                        })
                },
                hotKey: function (city) {
                    this.city = city;
                    console.log(city);
                    this.getWeather();
                }
            }
        })
    </script>
</body>

</html>